package cn.com.zcode.exam.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.beans.BeanUtils;

import cn.com.zcode.attchment.model.Attachment;
import cn.com.zcode.core.model.BaseModelSupport;

public class Question extends BaseModelSupport {
	private static final long serialVersionUID = 1L;
	private Paper paper;
	private Integer no;
	private String cnSummary;
	private String enSummary;
	private String analysis;
	private String answer;
	private String ptype;
	private String chapter;
	private Wrong wrong;
	private List<Option> options = new ArrayList<Option>();
	private Set<Attachment> attchments = new HashSet<Attachment>();
	
	public Question(Question question,Wrong wrong) {
		super();
		BeanUtils.copyProperties(question, this);
		this.wrong = wrong;
	}
	public Paper getPaper() {
		return paper;
	}
	public void setPaper(Paper paper) {
		this.paper = paper;
	}

	private Map<String,Option> mapopts = new HashMap<String, Option>();

	public Question() {
		super();
	}

	public Integer getNo() {
		return no;
	}

	public void setNo(Integer no) {
		this.no = no;
	}

	public String getCnSummary() {
		return cnSummary;
	}

	public void setCnSummary(String cnSummary) {
		this.cnSummary = cnSummary;
	}

	public String getEnSummary() {
		return enSummary;
	}

	public void setEnSummary(String enSummary) {
		this.enSummary = enSummary;
	}

	public String getAnalysis() {
		return analysis;
	}

	public void setAnalysis(String analysis) {
		this.analysis = analysis;
	}

	public String getAnswer() {
		return answer;
	}

	public void setAnswer(String answer) {
		this.answer = answer;
	}

	public List<Option> getOptions() {
		return options;
	}

	public void setOptions(List<Option> options) {
		this.options = options;
	}

	public void addOption(Option option) {
		 this.options.add(option);
		 this.mapopts.put(option.getNo(), option);
	}
	public Option getOption(String no){
		return this.mapopts.get(no);
	}
	
	public boolean hasOptions() {
		 
		return !this.options.isEmpty();
	}

	public String getChapter() {
		return chapter;
	}

	public void setChapter(String chapter) {
		this.chapter = chapter;
	}

	public String getPtype() {
		return ptype;
	}

	public void setPtype(String ptype) {
		this.ptype = ptype;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((analysis == null) ? 0 : analysis.hashCode());
		result = prime * result + ((answer == null) ? 0 : answer.hashCode());
		result = prime * result + ((chapter == null) ? 0 : chapter.hashCode());
		result = prime * result + ((cnSummary == null) ? 0 : cnSummary.hashCode());
		result = prime * result + ((enSummary == null) ? 0 : enSummary.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());;
		result = prime * result + no;
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Question other = (Question) obj;
		if (analysis == null) {
			if (other.analysis != null)
				return false;
		} else if (!analysis.equals(other.analysis))
			return false;
		if (answer == null) {
			if (other.answer != null)
				return false;
		} else if (!answer.equals(other.answer))
			return false;
		if (chapter == null) {
			if (other.chapter != null)
				return false;
		} else if (!chapter.equals(other.chapter))
			return false;
		if (cnSummary == null) {
			if (other.cnSummary != null)
				return false;
		} else if (!cnSummary.equals(other.cnSummary))
			return false;
		if (enSummary == null) {
			if (other.enSummary != null)
				return false;
		} else if (!enSummary.equals(other.enSummary))
			return false;
		if (id != other.id)
			return false;
		if (no != other.no)
			return false;
		return true;
	}
	public Wrong getWrong() {
		return wrong;
	}
	public void setWrong(Wrong wrong) {
		this.wrong = wrong;
	}
	public Set<Attachment> getAttchments() {
		return attchments;
	}
	public void setAttchments(Set<Attachment> attchments) {
		this.attchments = attchments;
	}
	 
	 
	 
 
}
